<!DOCTYPE html>
<html>
<head>
    <title>备件清单</title>
    #parse("sys/header.html")
</head>
<body>
<div id="rrapp" v-cloak>
    <div >
        <Row :gutter="16" style="margin: 8px 0px 0px 1px">
            <div class="search-group">
                <i-col span="4">
                    <i-input v-model="q.partName" @on-enter="query" placeholder="备件名称"></i-input>
                </i-col>
                <i-col span="4">
                    <i-input v-model="q.spec" @on-enter="query" placeholder="规格"></i-input>
                </i-col>
                <i-col span="4">
                    <i-input v-model="q.partCode" @on-enter="query" placeholder="系统编码"></i-input>
                </i-col>
                <i-col span="4">
                    <i-input v-model="q.producor" @on-enter="query" placeholder="生产厂家"></i-input>
                </i-col>
                <i-button @click="query">查询</i-button>
                <i-button @click="reloadSearch">重置</i-button>
            </div>
        </Row>
        <table id="jqGrid"></table>
    </div>
</div>
<script>
    $(function () {
        $("#jqGrid").Grid({
            url: '../sparepart/list?isValid=1&status=1',
            colModel: [
                {label: '系统编码', name: 'partCode', index: 'PART_CODE', width: 80},
                {label: '备件名称', name: 'name', index: 'NAME', width: 80},
                {label: '规格', name: 'spec', index: 'SPEC', width: 100},
                {label: '单位', name: 'unit', index: 'UNIT', width: 40},
                {label: '生产厂家', name: 'producor', index: 'PRODUCOR', width: 80},
                {label: '使用单位', name: 'useUnit', index: 'USE_UNIT', width: 80},
                {label: 'ERP编码', name: 'erpCode', index: 'ERP_CODE', width: 60},
                {label: '库存数量', name: 'stockNum', index: 'STOCK_NUM', width: 60},
                {
                    label: '创建时间', name: 'createDate', index: 'CREATE_DATE', width: 80, formatter: function (value) {
                        return transDate(value,'yyyy-MM-dd');
                    }
                },
                {label: 'id', name: 'id', index: 'ID', key: true, hidden: true}
            ]
        });
    });

    let vm = new Vue({
        el: '#rrapp',
        data: {
            q: {
                partCode: '',
                name: '',
                spec:'',
                producor:''
            }
        },
        methods: {
            query: function () {
                vm.reload();
            },
            reload: function (event) {
                // 清楚postData缓存
                var postData = $("#jqGrid").jqGrid("getGridParam", "postData");
                $.each(postData, function (k, v) {
                    delete postData[k];
                });
                let page = $("#jqGrid").jqGrid('getGridParam', 'page');
                $("#jqGrid").jqGrid('setGridParam', {
                    search: true,
                    postData:vm.q,
                    page: page
                }).trigger("reloadGrid");
            },
            reloadSearch: function () {
                vm.q = {
                    partCode: '',
                    name: '',
                    spec:'',
                    producor:''
                };
                vm.reload();
            },
            handleSubmit: function (name) {
                handleSubmitValidate(this, name, function () {
                    vm.saveOrUpdate()
                });
            },
            handleReset: function (name) {
                handleResetForm(this, name);
            }
        }
    });
    // 获取选中备件列表
    var getSparePart = function () {
        return getSelectedRowData("#jqGrid");
    }
    // 获取所有已选备件ID列表
    var getSelectedSpareParts = function () {
        return getSelectedRows("#jqGrid");
    }
</script>

</body>
</html>
